<template>
  <div class="client">
    <h1>客户信息列表</h1>

    <el-form :inline="true" class="demo-form-inline" @submit.native.prevent>
      <el-form-item>
        <el-input prefix-icon="el-icon-search" v-model="keyword" @keyup.enter.native="searchInfo()" placeholder="搜索姓名"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="searchInfo()">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="tableData" style="width: 100%;text-align:center;">
      <el-table-column label="姓名" width="100" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电话" width="180" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.phone }}</span>
        </template>
      </el-table-column>
      <el-table-column label="ID" width="400" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" @click="addLiveInfo(scope.$index, scope.row,scope.row.id)">编辑视频</el-button>
          <el-button size="mini" type="primary" @click="addAlbumInfo(scope.$index, scope.row,scope.row.id)">编辑相册</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination style="text-align: center;" background :total="total" :current-page.sync="currentPage" @current-change="changePage">
    </el-pagination>
  </div>
</template>

<script>
  export default {
    name: "client",
    data() {
      return {
        currentPage: 1,
        total: 0,
        keyword: "",
        tableData: [],
      };
    },
    created() {
      // 初始化页面
      this.api.get("/api/searchuser").then(res => {
        console.log(res, "yayaya");
        this.total = res.data.total;
        this.tableData = res.data.array;
      });
    },
    methods: {
      handleDelete(index, row) {
        //删除
      },
      addAlbumInfo(index, row, id) {
        //添加相册
        this.$router.push({
          path: "./addImg",
          query: {
            id: id
          }
        });
      },
      addLiveInfo(index, row, id) {
        //添加直播
        console.log(id, "id")
        this.$router.push({
          path: "/admin/mainstay/addLive",
          query: {
            id: id
          }
        });
      },
      // 分页
      changePage(val) {
        // 关键字
        let param = this.keyword;
        // 切换分页的时候判断是否有关键字
        if (param != "") {
          this.api.get('/api/searchuser?keyword=' + param + '&page=' + val).then((res) => {
            this.totla = res.data.total;
            this.tableData = res.data.array;
          })
        } else {
          this.api.get('/api/searchuser?page=' + val).then((res) => {
            this.totla = res.data.total;
            this.tableData = res.data.array;
          })
        }
      },

      // 搜索
      searchInfo() {
        let param = this.keyword;

        this.api.get("/api/searchuser?keyword=" + param).then(res => {
          console.log(res, '结果')
          this.currentPage = 1;
          this.total = res.data.total;
          this.tableData = res.data.array;
        });
      }
    }
  };
</script>
<style scoped>
</style>
